part of flutter_ezviz;

///回调函数
typedef void EventCallback(arg);
typedef void EzvizUIKitViewCreatedCallback(EzvizUIKitControl controller);

///丰富组件效果
class EzvizUIKitViewWidget extends StatefulWidget {
  ///
  String AppKey = "";
  String accessToken = "";
  String playUrl = "";
  EventCallback callback;
  EzvizUIKitViewCreatedCallback ezvizUIKitViewCreatedCallback;

  EzvizUIKitViewWidget(
      {this.accessToken,
      this.AppKey,
      this.playUrl,
      this.callback,
      this.ezvizUIKitViewCreatedCallback});

  @override
  _EzvizUIKitViewWidgetState createState() => _EzvizUIKitViewWidgetState();
}

class _EzvizUIKitViewWidgetState extends State<EzvizUIKitViewWidget> {
  ValueNotifier<bool> flag = ValueNotifier<bool>(false);
  Widget _hero;
  @override
  void initState() {
    SystemChrome.setPreferredOrientations( // 使设备横屏显示
        [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
    super.initState();
    _hero =Hero(
      tag: 'ezvizUI',
      child: EzvizUIKitView(
        AppKey: widget.AppKey,
        playUrl: widget.playUrl,
        callback: widget.callback,
        accessToken: widget.accessToken,
        ezvizUIKitViewCreatedCallback:
        widget.ezvizUIKitViewCreatedCallback,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Stack(
        children: [
          Container(
            color: Colors.black,
            child: _hero
          ),
          Positioned.fill(
              child: ValueListenableBuilder(
            valueListenable: flag,
            builder: (_, value, __) {
              return GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTap: () {
                  print("111111");

                  ///展示
                  flag.value = !flag.value;
                },
                child: Container(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Container(),
                      Container(
                        color: Colors.black45,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Container(),

                            ///
                            Visibility(
                                visible: value,
                                child: Padding(
                                  padding: EdgeInsets.all(0),
                                  child: IconButton(
                                      icon: Icon(
                                        Icons.fullscreen,
                                        color: Colors.white,
                                        size: 30,
                                      ),
                                      onPressed: () {
                                        Navigator.of(context)
                                            .push(MaterialPageRoute(builder: (context) {
                                          return FullScreen(hero:_hero);
                                        }));
                                      }),
                                ))
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              );
            },
          )),
        ],
      ),
    );
  }
}
